﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.enprise
{
    public partial class ModifyHunter : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心—猎头职位：猎头职位查看、修改  {0}", Application["webname"].ToString());
                }
                if (Session["enterprise_aid"] != null)
                {
                    if (Session["enterprise_name"] != null)
                    {
                        this.lbl_title.Text = " " + Session["enterprise_name"].ToString();
                    }


                    int enterprise_aid = Convert.ToInt32(Session["enterprise_aid"]);

                    ShowInfo(enterprise_aid);
                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            if (Session["enterprise_aid"] != null)
            {
                int enterprise_aid = Convert.ToInt32(Session["enterprise_aid"]);

                Save(enterprise_aid);
            }
        }

        private void ShowInfo(int enterprise_aid)
        {
            lcmyjobs.BLL.enterprise_askhunter bll = new lcmyjobs.BLL.enterprise_askhunter();
            lcmyjobs.Model.enterprise_askhunter model = bll.GetModel(enterprise_aid);
            //this.hid.Text = model.enterprise_aid.ToString();
            this.hid_bid.Value = model.enterprise_bid.ToString();
            this.hid_bh.Value = model.enterprise_bh;
            this.txthunter_time.Text = model.hunter_time.ToString();
            this.hid_issuccess.Value = model.issuccess.ToString();
            this.hid_status.Value = model.status.ToString();
            this.txthunter_time.Text = model.hunter_time.ToString();
            this.txthuntername.Text = model.jobsname;
            this.txthuntervalidity.Text = model.hunter_validity.ToString();
            this.txtsalaryy.Text = model.salaryy;
            this.hid_rid.Value = model.enterprise_rid.ToString();


        }

        private void Save(int enterprise_aid)
        {
            //int enterprise_aid = int.Parse(this.lblenterprise_aid.Text);
            int enterprise_bid = int.Parse(this.hid_bid.Value);
            string enterprise_bh = this.hid_bh.Value;
            DateTime hunter_time = DateTime.Parse(this.txthunter_time.Text);
            bool issuccess = Convert.ToBoolean(this.hid_issuccess.Value);
            int status = int.Parse(this.hid_status.Value);
            string salaryy = this.txtsalaryy.Text;
            int valadity = Convert.ToInt32(this.txthuntervalidity.Text);
            int enterprise_rid = Convert.ToInt32(this.hid_rid.Value);

            lcmyjobs.Model.enterprise_askhunter model = new lcmyjobs.Model.enterprise_askhunter();
            model.enterprise_aid = enterprise_aid;
            model.enterprise_bid = enterprise_bid;
            model.enterprise_bh = enterprise_bh;
            model.hunter_time = hunter_time;
            model.issuccess = issuccess;
            model.status = status;
            model.salaryy = salaryy;
            model.hunter_validity = valadity;
            model.enterprise_rid = enterprise_rid;


            lcmyjobs.BLL.enterprise_askhunter bll = new lcmyjobs.BLL.enterprise_askhunter();
            if (bll.Update(model))
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "修改猎头职位成功！", "ListHunter.html");

            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "修改猎头职位失败！", "ListHunter.html");

            }

        }
    }
}